<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #tip{
            width: 200px;
            height: 20px;
            border: solid 1px #eee;
            background-color: #eee;
            text-align: center;
            padding: 4px;
            line-height: 50px;
        }
        #txt{
            margin-left: 15px;
            text-align: center;
        }
    </style>
</head>
<body>
    <div id="tip"></div>
    <input type="text" id="txt">
    <script>
        //获取input和div元素
        var objTip=document.getElementById("tip");
        var objTxt=document.getElementById("txt");
        objTxt.oninput=function(){
            //objTip.innerText = objTxt.value.toUpperCase(); //大写
            //objTip.innerText = objTxt.value.charAt(0);  //第一个字符
            //objTip.innerText = objTxt.value.charAt(1);  //第二个字符
            //获取查询结果
            // objTip.innerText = objTxt.value.indexOf('a'); //找到返回索引，未找到返回-1
            // objTip.innerText = objTxt.value.lastIndexOf('a');   //从后向前查找，返回索引或-1
            var sp = objTxt.value.indexOf('a');
            var s = objTxt.value.lastIndexOf('a');
            objTip.innerText = objTxt.value.substring(sp,s); //返回以a开头，以a截止的字符串
            var str = "ie=utf-8&f=3&rsv_bp=1&rsv_idx=1&tn=baidu"
            //字符串分割
            var arr2 = str.split("&");
            for(var i=0;i<arr2.length;i++){
                var arr3 = arr2[i].split('=');
                console.log(arr3.toString());
                if(arr3[0]=='tn'){
                    console.log(arr3[1])
                }
            }
        }
    </script>
</body>
</html>